package com.wolfalpha.lwtool.service.impl;

import java.util.List;
import java.util.Map;

import com.wolfalpha.lwtool.constant.Application;
import com.wolfalpha.lwtool.constant.Constant;
import com.wolfalpha.lwtool.service.ZQService;
import com.wolfalpha.lwtool.util.JsonUtil;
import com.wolfalpha.lwtool.vo.InfoJson;
import com.wolfalpha.lwtool.vo.Job;
import com.wolfalpha.lwtool.vo.JobInfo;
import com.wolfalpha.lwtool.vo.JobJson;

/**
 * 抓取服务实例
 * @author ttStudio
 *
 */
public class ZQServiceImpl implements ZQService {
	
	
//	@Override
//	public List<Job> getJobList(int category) throws ParseException, IOException  {
//		HttpResponse message = null;
//		try {
//			message = Application.getClient().unSafeIdmpRequest(
//							"http://app.fafajob.com/parttimeJob/list.do",
//							new BasicNameValuePair("competenceCode", "w1T01f5AlH5zpGyaQLW9zOVf%2BlcMExInMtzDIgeA2aA%3D%0A"),
//							new BasicNameValuePair("provincesName", "江苏省"),
//							new BasicNameValuePair("cityName","南京市"),
//							new BasicNameValuePair("pjType","ordinary"),
//							new BasicNameValuePair("apiType","index"),
//							new BasicNameValuePair("sign","612303b8e1ef25981a5178b3d3ef8ad"),
//							new BasicNameValuePair("longitude","118.781809"),
//							new BasicNameValuePair("latitude","32.050058"),
//							new BasicNameValuePair("client_type","app_client"),
//							new BasicNameValuePair("jobNature",""),
//							new BasicNameValuePair("paymentMeans",""),
//							new BasicNameValuePair("jobNature",""),
//							new BasicNameValuePair("jobNature","")
//					);
//		} catch (Exception e) {
//		}
//		if(message == null)return null;
//		int status = message.getStatusLine().getStatusCode();
//		if (status == 200) {
//			String data = EntityUtils.toString(message.getEntity());
//			System.out.println(data);
////			java.lang.reflect.Type type = new TypeToken<ArrayList<Job>>() {
////			}.getType();
////			List<Job> jobList = JsonUtil.parseJson(data, type);
////			return jobList;
//		} else {
//		}
//		return null;
//	}
	
	
	@Override
	public List<Job> getJobs(String strUrlPath, Map<String, String> params) {
		String data = Application.getClient().submitPostData(strUrlPath, params, Constant.encode);
		JobJson jjson = JsonUtil.parseJson(data, JobJson.class);
		return jjson.getJobs();
	}
	
	@Override
	public List<Job> getMoreJobs(String strUrlPath, Map<String, String> params) {
		String data = Application.getClient().submitPostData(strUrlPath, params, Constant.encode);
		JobJson jjson = JsonUtil.parseJson(data, JobJson.class);
		return jjson.getJobs();
	}
	
	@Override
	public JobInfo getInfo(String strUrlPath, Map<String, String> params) {
		String data = Application.getClient().submitPostData(strUrlPath, params, Constant.encode);
		InfoJson jjson = JsonUtil.parseJson(data, InfoJson.class);
		return jjson.getParttimeJob();
	}

	@Override
	public String postData(String strUrlPath, Map<String, String> params){
		String data = Application.getClient().submitPostData(strUrlPath, params, Constant.encode);
		return data;
	}
	
	@Override
	public List<Job> getRefreshJobs(String strUrlPath,
			Map<String, String> params) {
		String data = Application.getClient().submitPostData(strUrlPath, params, Constant.encode);
		JobJson jjson = JsonUtil.parseJson(data, JobJson.class);
		return jjson.getJobs();
	}
	
	
}
